import { Cover } from "../canvas/System/Cover";

import { ToolHub } from "../ToolBox/Tool";
import { useControllerStore } from "../Controller/Controller";

/** 提供停止方式的拖拽填充 */
export function DragPaint(cover: Cover) {
    return async (position: { x: number; y: number }) => {
        const { x, y } = cover.toLocal(position);
        const X = Math.floor(x);
        const Y = Math.floor(y);
        const layers = useControllerStore().selectedLayer;
        const trueLayers = cover.canvas.layerManager.layers;
        layers.forEach(({ id }) => {
            const layer = trueLayers.get(id)!;
            ToolHub.emit("usePaintFill", { x: X, y: Y, layer });
        });
    };
}
